import * as Service from '../services/cardProcess';
export default {

    namespace: 'cardProcess',

    state: {
        // timer: Date.parse(new Date()),
        fristCheck: false,
        Onestate: false,
        Twostate: false,
        Threestate: false,
        Fourstate: false,
        Fivestate: false,
        fourthCheck: false,
        phoneNumber: '', // 手机号
        code: '',  // 验证码
        position: '', // 职业
        location: '', // 地址
        password: '', // 密码
        passwordAgain: '',
        YXT: false,
        ATM: false,
        mobileBank: false,
        webBank: false,
    },

    subscriptions: {
        setup({ dispatch, history }) {  // eslint-disable-line
        },
    },

    effects: {
        *fristCheck({ payload: _State }, { put }) {
            yield put({
                type: 'connect',
                payload: {
                    fristCheck: _State.checked,
                    Onestate: _State.Onestate
                }
            })
        },
        *fourthCheck({ payload: _State }, { put }) {
            yield put({
                type: 'connect',
                payload: {
                    fourthCheck: _State.checked,
                }
            })
        },
        *infoSave({ payload: _State }, { call, put }) {  // eslint-disable-line
            yield put({
                type: 'connect',
                payload: {
                    phoneNumber: _State.phoneNumber,
                    code: _State.code,
                    postcode: _State.postcode,
                    position: _State.position,
                    Twostate: _State.Twostate,
                    location: _State.location,
                }
            });
        },
        *pwd({ payload: _State }, { call, put }) {  // eslint-disable-line
            yield put({
                type: 'connect',
                payload: {
                    password: _State.password,
                    passwordAgain: _State.passwordAgain,
                    Threestate: _State.Threestate
                }
            });
        },
        *clear({ payload: _State }, { call, put }) {  // eslint-disable-line
            yield put({
                type: 'connect',
                payload: {
                    fristCheck: false,
                    Onestate: false,
                    Twostate: false,
                    // Threestate: false,
                    Fourstate: false,
                    Fivestate: false,
                    fourthCheck: false,
                    phoneNumber: '',
                    code: '',
                    position: '',
                    location: '',
                    password: '',
                    passwordAgain: '',
                    YXT: false,
                    ATM: false,
                    mobileBank: false,
                    webBank: false,
                    postDataResult:null,
                    spinState:false
                }
            });
        },
        *check({ payload: _State }, { call, put }) {  // eslint-disable-line
            yield put({
                type: 'connect',
                payload: {
                    YXT: _State.YXT,
                    ATM: _State.ATM,
                    mobileBank: _State.mobileBank,
                    webBank: _State.webBank,
                    Fourstate: _State.Fourstate,
                }
            });
        },
        *postResult({ payload: _State }, { call, put }){
            yield put({
                type: 'connect',
                payload: {
                    postDataResult:_State
                }
            });
        },
        *spinState({ payload: _State }, { call, put }){
            yield put({
                type: 'connect',
                payload: {
                    spinState: _State.spinState
                }
            });
        },
        *sendCard(action, { call, put }) { // 发卡
            const data = yield call(Service.query, { type: 'sendCard' });
            yield put({
                type: 'connect',
                payload: {
                    sendCard: data.result
                }
            });
        },

    },

    reducers: {
        connect(state, action) {
            return { ...state, ...action.payload };
        },
    },

};
